package com.etc.service.impl;

import com.etc.mapper.NewsDao;
import com.etc.pojo.News;
import com.etc.service.NewsDaoServices;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: RookieSocialNetworking
 * @description:
 * @author: Mr.单
 * @create: 2020-08-14 19:53
 **/
@Service()
public class NewsDaoServicesImpl implements NewsDaoServices {

    @Autowired
    NewsDao dao;

    public NewsDaoServicesImpl(NewsDao dao) {
        this.dao = dao;
    }

    @Override
    public boolean pushNews(News news) {
        return dao.addNews(news)== 0 ? false : true;
    }

    @Override
    public List<News> getallNews() {
        return dao.queryallNews();
    }

    @Override
    public PageInfo<News> getPageAllNews(Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<News> news = dao.queryPageAllNews();
        PageInfo<News> page = new PageInfo(news);
        return page;
    }

    @Override
    public boolean deleteN(int newsId) {
        return dao.deleteNews(newsId)== 0 ? false : true;
    }

    @Override
    public List<News> getNewsByLike(int userId,String newsDetail, int pageNum, int size) {
        PageHelper.startPage(pageNum,size);
        return dao.queryNewsByLike(userId,newsDetail);
    }
}
